package com.leoman.dao;

import com.leoman.entity.Video;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 视频
 * Created by Administrator on 2016/10/18 0018 下午 3:05.
 */
public interface VideoDao extends JpaRepository<Video, Integer>, JpaSpecificationExecutor<Video> {

    @Query("select a from Video a where a.videoType.id = ?1")
    List<Video> findListByVideoTypeId(Integer videoTypeId);

    @Query("select a from Video a where a.videoType.id = ?1 and a.isShopping = 1 and a.checkStatus = 1 and a.recordStatus = 1")
    List<Video> findListByVideoTypeIdDefault(Integer videoTypeId);

    @Query("select a from Video a where a.createTime >= ?1")
    List<Video> findListByCreateTime(Long createTime);

    @Query("select a from Video a where a.checkStatus = ?1")
    List<Video> findListByCheckStatus(Integer checkStatus);

    @Query("select a from Video a where a.checkStatus = 1 and a.isShopping = ?1")
    List<Video> findListByIsShopping(Integer shopping);

    @Query("select a from Video a where a.recordStatus = ?1")
    List<Video> findListByRecordStatus(Integer recordStatus);

    @Query("select a from Video a where a.companyUser.id = ?1")
    Page<Video> iPageByCompanyUserId(Integer companyUserId, Pageable pageable);

    @Query("select a from Video a where a.companyUser.id = ?1 and a.checkStatus = ?2")
    List<Video> findListByCompanyUserIdAndCheckStatus(Integer companyUserId, Integer checkStatus);

    @Query("select a from Video a where a.companyUser.id = ?1 and a.checkStatus = 1 and a.recordStatus = ?2")
    List<Video> findListByCompanyUserIdAndRecordStatus(Integer companyUserId, Integer recordStatus);

    @Query("select a from Video a where a.companyUser.id = ?1 and a.sendType = ?2")
    List<Video> findListByCompanyUserIdAndSendType(Integer companyUserId, Integer sendType);

    @Query("select a from Video a where a.companyUser.id = ?1")
    List<Video> findListByCompanyUserId(Integer companyUserId);

    @Query("select a from Video a where a.companyUser.id = ?1 and a.checkStatus = ?2")
    Page<Video> pageByCompanyUserIdAndCheckStatus(Integer companyUserId, Integer checkStatus, Pageable pageable);

    @Query("select a from Video a where a.companyUser.id = ?1 and a.recordStatus = ?2")
    Page<Video> pageByCompanyUserIdAndRecordStatus(Integer companyUserId, Integer status, Pageable pageable);
}